home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TDE.ARJ / TDE.H < prev    next >
C/C++ Source or Header  |  1992-07-14  |  15KB  |  407 lines

  1. /***************************************************************************
  2.  
  3.  FILENAME - TDE.H: Header file for classes:
  4.  ----------------
  5.             To use this class:    #define this (before #included TDE.H):
  6.             ------------------    --------------------------------------
  7.                      TDataEntry       (always included)
  8.                      TDEAlpha         Uses_TDEAlpha
  9.                      TDEAlphaNum      Uses_TDEAlphaNum
  10.                      TDENumeric       Uses_TDENumeric
  11.                      TDEInteger       Uses_TDEInteger
  12.                      TDEDate          Uses_TDEDate
  13.                      TDEPhone         Uses_TDEPhone
  14.                      TDEZipCode       Uses_TDEZipCode
  15.                      TDEState         Uses_TDEState
  16.                      TDEButton        Uses_TDEButton
  17.                      TDEInputLine     Uses_TDEInputLine
  18.                      TDERadioButtons  Uses_TDERadioButtons
  19.                      TDECheckBoxes    Uses_TDECheckBoxes
  20.  
  21.  Class TDataEntry v1.0 - 07/14/92
  22.  --------------------------------
  23.  
  24.  ----------------------------------------------------------------------------
  25.  Author: Jeff Penrose * JDP Custom Software * (818) 344-7303 * CIS 71043,3727
  26.  ----------------------------------------------------------------------------
  27.  
  28.  A data entry class for Borland's Turbo Vision, derived from TInputLine.
  29.  
  30.  Copyright Notice
  31.  ================
  32.   As this material is ultimately derived from Borland source files, any of
  33.  their copyrights which MAY apply DO apply.
  34.   From the author's standpoint, you may use this material freely and,
  35.  hopefully, post any comments/corrections/enhancements to me at the above-
  36.  noted addresses.  I do ask that you not distribute this material except as
  37.  originally received, including all source/documentation files in their
  38.  original form.
  39.   If you DO modify or enhance any of this code, please send any such changes
  40.  to me for incorporation into a future version.  Any such enhancements will
  41.  be DONATED, without expectation of compensation or incorporation into
  42.  future versions.  Again, if you distribute this code, please do so in its
  43.  original, unmodified form including all source files and documentation.
  44.  
  45. Source files included
  46. =====================
  47.  TDE     .DOC: This documentation.
  48.  TDE     .MAN: How to use TDataEntry in your dialog objects
  49.  TDE     .H  : header file containing class declarations for classes
  50.  TDEFLAGS.H  :   "     "      "       flags and command definitions
  51.  TDE     .CPP: Class TDataEntry
  52.  TDEDATE .CPP: Class TDEDate
  53.  TDEPHONE.CPP: Classes TDEPhone, TDEZipCode, TDEState
  54.  TDENUMS .CPP: Class TDEInteger
  55.  TDECLUST.CPP: Non-TDataEntry classes TDEButton, TDERadioButtons, TDECheckBoxes
  56.  TDEINPLI.CPP: Non-TDataEntry class TDEInputLine
  57.  TDELIB  .PRJ: Project for building library TDELIB.LIB
  58.  TDEDEMO .CPP: Demo program
  59.  TDEDEMO .PRJ: Project for building TDEDEMO.EXE
  60.  
  61. ***************************************************************************/
  62.  
  63. #if !defined( __T_DATA_ENTRY_H )
  64. #define  __T_DATA_ENTRY_H
  65.  
  66. #define Uses_TInputLine
  67. #define Uses_MsgBox
  68. #define Uses_TButton
  69. #define Uses_TRadioButtons
  70. #define Uses_TCheckBoxes
  71. #include <tv.h>
  72.  
  73. #if !defined(__CTYPE_H)  // for toupper(), isxxxx() macros
  74. #include <ctype.h>
  75. #endif
  76.  
  77. #include  "tdeflags.h"   // #define's for all the constants
  78.  
  79. #define  MASK_CHAR  '~'
  80.  
  81. //--------------------------------------------------------------------------
  82. //
  83. // **** class TDataEntry  ( TDE.CPP )
  84. //
  85. //--------------------------------------------------------------------------
  86. class TDataEntry : public TInputLine
  87. {
  88. public:
  89.   uchar   localMode;
  90.   ushort  dataFormat;
  91.   static  uchar   globalID;
  92.   static  ushort  globalMode;
  93.   static  char    *msgDataRequired;
  94.   static  char    *msgDataInvalid;
  95.   static  char    secureChar;
  96.  
  97.   TDataEntry(int col, int row, char *format, const char *fName = NULL );
  98.   TDataEntry(int col, int row, int len, const char *fName = NULL );
  99.   ~TDataEntry();
  100.   void selectAll( Boolean enable );
  101.   virtual ushort dataSize();
  102.   virtual void draw();
  103.   virtual void getData( void *rec );
  104.   virtual void handleEvent(TEvent& event);
  105.   virtual void setData( void *rec );
  106.   virtual void setState( ushort aState, Boolean enable );
  107.   virtual Boolean valid(ushort);
  108.   virtual Boolean validData( const char *InvalidMsg, char const *RequiredMsg );
  109.   virtual Boolean validKey(uchar *key ) { return (Boolean)isprint(*key); };
  110.   static  inline  TDataEntry *locateID( TView *fieldOwner, uchar fieldNumber,
  111.                                         Boolean select = False );
  112.   static  inline  TDataEntry *locateName( TView *fieldOwner, const char *fName,
  113.                                           Boolean select = False );
  114.   static  inline  void       resetData( TView *fieldOwner, TDataEntry *target = NULL );
  115.   static  inline  TDataEntry *queryChanged( TView *fieldOwner, TDataEntry *target = NULL );
  116.   static  inline  TDataEntry *queryValid( TView *fieldOwner, TDataEntry *target = NULL );
  117.  
  118. protected:
  119.   char    *mask, *outView, *origData;
  120.   int     tdCurPos, tdLastPos, tdSelStart, tdSelEnd;
  121.   ushort  localID;
  122.   char    *fieldName;
  123.  
  124. private:
  125.   int  mousePos( TEvent& event );
  126.   void deleteSelect();
  127.   void near setViewPos(ushort);
  128.   void near formatView();
  129. };
  130.  
  131. //--------------------------------------------------------------------------
  132. //
  133. // **** class TDEAlpha - alpha strings only  ( TDE.CPP )
  134. //
  135. //--------------------------------------------------------------------------
  136. #if defined( Uses_TDEAlpha )
  137. class TDEAlpha : public TDataEntry
  138. {
  139. public:
  140.   TDEAlpha(int col, int row, char *format, const char *fName = NULL) :
  141.     TDataEntry(col, row, format, fName) {};
  142.   TDEAlpha(int col, int row, int len, const char *fName = NULL) :
  143.     TDataEntry(col, row, len, fName) {};
  144.  
  145.   virtual Boolean validKey(uchar *key) { return (Boolean)isalpha(*key); };
  146.   virtual Boolean validData( char *, char * )
  147.   { return
  148.     TDataEntry::validData( "\003Data must be alpha characters only!", NULL);
  149.   };
  150. };
  151. #endif
  152.  
  153. //--------------------------------------------------------------------------
  154. //
  155. // **** class TDEAlphaNum - alphanumeric strings only  ( TDE.CPP )
  156. //
  157. //--------------------------------------------------------------------------
  158. #if defined( Uses_TDEAlphaNum )
  159. class TDEAlphaNum : public TDataEntry
  160. {
  161. public:
  162.   TDEAlphaNum(int col, int row, char *format, const char *fName = NULL) :
  163.     TDataEntry(col, row, format, fName) {};
  164.   TDEAlphaNum(int col, int row, int len, const char *fName = NULL) :
  165.     TDataEntry(col, row, len, fName) {};
  166.  
  167.   virtual Boolean validKey(uchar *key) { return (Boolean)isalnum(*key); };
  168.   virtual Boolean validData( const char *, const char * )
  169.   { return
  170.     TDataEntry::validData( "\003Data must be alphanumeric characters only!", NULL);
  171.   };
  172. };
  173. #endif
  174.  
  175. //--------------------------------------------------------------------------
  176. //
  177. // **** class TDENumeric - numeric strings only  ( TDE.CPP )
  178. //
  179. //--------------------------------------------------------------------------
  180. #if defined( Uses_TDENumeric )
  181. class TDENumeric : public TDataEntry
  182. {
  183. public:
  184.   TDENumeric(int col, int row, char *format, const char *fName = NULL) :
  185.     TDataEntry(col, row, format, fName), SpaceAllowed( False ) {};
  186.   TDENumeric(int col, int row, int len, const char *fName = NULL) :
  187.     TDataEntry(col, row, len, fName), SpaceAllowed( False ) {};
  188.  
  189.   Boolean SpaceAllowed;
  190.  
  191.   virtual Boolean validKey(uchar *key)
  192.     { return (Boolean) ( (*key == ' ' && SpaceAllowed) || isdigit(*key)); };
  193.   virtual Boolean validData( const char *, const char * )
  194.   { return
  195.     TDataEntry::validData( "\003Data must be numeric only!", NULL);
  196.   };
  197. };
  198. #endif
  199.  
  200. //--------------------------------------------------------------------------
  201. //
  202. // **** class TDEInteger - signed integer values ( TDEDATE.CPP )
  203. //
  204. //--------------------------------------------------------------------------
  205. #if defined( Uses_TDEInteger )
  206. class TDEInteger : public TDataEntry
  207. {
  208. public:
  209.   TDEInteger(int col, int row, char *format, const char *fName = NULL) :
  210.     TDataEntry(col, row, format, fName) {};
  211.   TDEInteger(int col, int row, int len, const char *fName = NULL) :
  212.     TDataEntry(col, row, len, fName) {};
  213.  
  214.   virtual void    getData(void *);
  215.   virtual void    setData(void *);
  216.   virtual ushort  dataSize() { return sizeof( int ); };
  217.   virtual void    handleEvent( TEvent& event );
  218.   virtual Boolean validData( const char *, const char * );
  219.   virtual Boolean validKey(uchar *key) { return (Boolean)isdigit(*key); };
  220. protected:
  221.   int     origInt;
  222. };
  223. #endif
  224.  
  225. //--------------------------------------------------------------------------
  226. //
  227. // **** class TDEDate - date strings only (TDEDATE.CPP)
  228. //
  229. //--------------------------------------------------------------------------
  230. #if defined( Uses_TDEDate )
  231.  
  232. #define  dateMDY  0x01
  233. #define  dateYMD  0x02
  234. #define  dateDMY  0x03
  235.  
  236. class TDEDate : public TDataEntry
  237. {
  238. public:
  239.   TDEDate(int col, int row, char *format, const char *fName = NULL) :
  240.     TDataEntry(col, row, format, fName) {};
  241.   TDEDate(int col, int row, int len, const char *fName = NULL) :
  242.     TDataEntry(col, row, len, fName) {};
  243.  
  244.   static  ushort  defCentury;
  245.   static  ushort  dateFormat;
  246.   virtual ushort  dataSize() { return sizeof( long ); };
  247.   virtual void    getData( void *rec );
  248.   virtual void    setData( void *rec );
  249.   virtual Boolean valid(ushort cmd);
  250.   virtual Boolean validData( const char *, const char * );
  251.   virtual Boolean validKey(uchar *key) { return (Boolean)isdigit(*key); };
  252. };
  253. #endif
  254.  
  255. //--------------------------------------------------------------------------
  256. //
  257. // **** class TDEPhone - phone number strings only (TDEPHONE.CPP)
  258. //
  259. //--------------------------------------------------------------------------
  260. #if defined( Uses_TDEPhone )
  261. class TDEPhone : public TDataEntry
  262. {
  263. public:
  264.   TDEPhone(int col, int row, char *format, const char *fName = NULL) :
  265.     TDataEntry(col, row, format, fName) {};
  266.   TDEPhone(int col, int row, int len, const char *fName = NULL) :
  267.     TDataEntry(col, row, len, fName) {};
  268.  
  269.   virtual Boolean valid(ushort cmd);
  270.   virtual Boolean validData( const char *, const char * );
  271.   virtual Boolean validKey(uchar *key) { return (Boolean)isdigit(*key); };
  272. };
  273. #endif
  274.  
  275. //--------------------------------------------------------------------------
  276. //
  277. // **** class TDEZipCode - zip code strings only (TDEPHONE.CPP)
  278. //
  279. //--------------------------------------------------------------------------
  280. #if defined( Uses_TDEZipCode )
  281. class TDEZipCode : public TDataEntry
  282. {
  283. public:
  284.   TDEZipCode(int col, int row, char *format, const char *fName = NULL) :
  285.     TDataEntry(col, row, format, fName) {};
  286.   TDEZipCode(int col, int row, int len, const char *fName = NULL) :
  287.     TDataEntry(col, row, len, fName) {};
  288.  
  289.   virtual Boolean valid(ushort cmd);
  290.   virtual Boolean validData( const char *, const char * );
  291.   virtual Boolean validKey(uchar *key) { return (Boolean)isdigit(*key); };
  292. };
  293. #endif
  294.  
  295. //--------------------------------------------------------------------------
  296. //
  297. // **** class TDEState - state abbreviation strings only (TDEPHONE.CPP)
  298. //
  299. //--------------------------------------------------------------------------
  300. #if defined( Uses_TDEState)
  301. class TDEState : public TDataEntry
  302. {
  303. public:
  304.   TDEState(int col, int row, char *format, const char *fName = NULL) :
  305.     TDataEntry(col, row, format, fName) {};
  306.   TDEState(int col, int row, int len, const char *fName = NULL) :
  307.     TDataEntry(col, row, len, fName) {};
  308.  
  309.   virtual Boolean valid(ushort cmd);
  310.   virtual Boolean validData( const char *, const char * );
  311.   virtual Boolean validKey(uchar *key)
  312.     { return (Boolean)isalpha(*key = toupper(*key)); };
  313. };
  314. #endif
  315.  
  316. //--------------------------------------------------------------------------
  317. //
  318. // **** class TDEButton ( TDECLUST.CPP )
  319. //
  320. // TButton control for use with dialogs containing TDataEntry objects when
  321. //  globalMode's tdgUpDownEnable flag is set.  Allows button to respond to
  322. //  up/down arrow movement.
  323. //--------------------------------------------------------------------------
  324. #if defined( Uses_TDEButton )
  325. class TDEButton : public TButton
  326. {
  327. public:
  328.   TDEButton::TDEButton( const TRect& bounds, const char *aTitle,
  329.                         ushort aCommand, ushort aFlags ) :
  330.              TButton( bounds, aTitle, aCommand, aFlags ) { };
  331.  
  332.   virtual void handleEvent( TEvent& event );
  333. };
  334. #endif
  335.  
  336. //--------------------------------------------------------------------------
  337. //
  338. // **** class TDEInputLine  ( TDEINPLI.CPP )
  339. //
  340. // TInputLine for use with dialogs containing TDataEntry objects when
  341. //  globalMode's tdgUpDownEnable flag is set.  Allows input line to respond
  342. //  to up/down arrow movement.
  343. //--------------------------------------------------------------------------
  344. #if defined( Uses_TDEInputLine )
  345. class TDEInputLine : public TInputLine
  346. {
  347. public:
  348.   TDEInputLine( const TRect& bounds, int aMaxLen, const char *fName = NULL );
  349.   ~TDEInputLine();
  350.  
  351.   virtual void     handleEvent( TEvent& event );
  352.   virtual void     getData( void * );
  353.   virtual void     setData( void * );
  354.   virtual void     setState( ushort aState, Boolean enable );
  355.   virtual Boolean  valid( ushort );
  356. protected:
  357.   char   *origData, *fieldName;
  358.   ushort localID;
  359.  
  360. };
  361. #endif
  362.  
  363. //--------------------------------------------------------------------------
  364. //
  365. // **** class TDERadioButtons  ( TDECLUST.CPP )
  366. //
  367. // TRadioButtons for use with dialogs containing TDataEntry objects when
  368. //  globalMode's tdgEnterIsTab flag is set.  Allows radio buttons to respond
  369. //  to enter key without exiting dialog.
  370. //--------------------------------------------------------------------------
  371. #if defined( Uses_TDERadioButtons )
  372. class TDERadioButtons : public TRadioButtons
  373. {
  374. public:
  375.   TDERadioButtons( const TRect& bounds, TSItem *aStrings, const char *fName = NULL );
  376.   ~TDERadioButtons();
  377.   virtual void handleEvent( TEvent& event );
  378.   virtual void setData( void * );
  379. protected:
  380.   ushort  origData, localID;
  381.   char    *fieldName;
  382. };
  383. #endif
  384.  
  385. //--------------------------------------------------------------------------
  386. //
  387. // **** class TDECheckBoxes  ( TDECLUST.CPP )
  388. //
  389. // TCheckBoxes for use with dialogs containing TDataEntry objects when
  390. //  globalMode's tdgEnterIsTab flag is set.  Allows check boxes to respond to
  391. //  enter key without exiting dialog.
  392. //--------------------------------------------------------------------------
  393. #if defined( Uses_TDECheckBoxes )
  394. class TDECheckBoxes : public TCheckBoxes
  395. {
  396. public:
  397.   TDECheckBoxes( const TRect& bounds, TSItem *aStrings, const char *fName = NULL );
  398.   ~TDECheckBoxes();
  399.   virtual void handleEvent( TEvent& event );
  400.   virtual void setData( void * );
  401. protected:
  402.   ushort  origData, localID;
  403.   char    *fieldName;
  404. };
  405. #endif
  406.  
  407. #endif